package cn.iocoder.yudao.module.member.dal.mysql.curriculumVitaeSendRecord;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.member.dal.dataobject.curriculumVitaeSendRecord.CurriculumVitaeSendInviteRecordDO;
import cn.iocoder.yudao.module.member.dal.dataobject.curriculumVitaeSendRecord.CurriculumVitaeSendRecordDO;
import cn.iocoder.yudao.module.member.dal.dataobject.curriculumVitaeSendRecord.CurriculumVitaeSendRecordGroupDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.member.controller.admin.curriculumVitaeSendRecord.vo.*;
import org.apache.ibatis.annotations.Param;

/**
 * 简历投递记录 Mapper
 *
 * @author 谭万全
 */
@Mapper
public interface CurriculumVitaeSendRecordMapper extends BaseMapperX<CurriculumVitaeSendRecordDO> {

    default PageResult<CurriculumVitaeSendRecordDO> selectPage(CurriculumVitaeSendRecordPageReqVO reqVO){
        boolean isAge=null==reqVO.getBginAge()||reqVO.getBginAge()<=0;
        return pageQuery(reqVO, new LambdaQueryWrapperX<CurriculumVitaeSendRecordDO>()
                .eqIfPresent(CurriculumVitaeSendRecordDO::getCompanyId, reqVO.getCompanyId())
                .eqIfPresent(CurriculumVitaeSendRecordDO::getStudentId, reqVO.getStudentId())
                .eqIfPresent(CurriculumVitaeSendRecordDO::getResumeId, reqVO.getResumeId())
                .eqIfPresent(CurriculumVitaeSendRecordDO::getJobId, reqVO.getJobId())
                .eqIfPresent(CurriculumVitaeSendRecordDO::getId, reqVO.getId())
                .eqIfPresent(CurriculumVitaeSendRecordDO::getSendType, reqVO.getSendType())
                .likeIfPresent(CurriculumVitaeSendRecordDO::getJobName, reqVO.getJobName())
                .likeIfPresent(CurriculumVitaeSendRecordDO::getCompanyName, reqVO.getCompanyName())
                .likeIfPresent(CurriculumVitaeSendRecordDO::getPublisherName, reqVO.getPublisherName())
                .likeIfPresent(CurriculumVitaeSendRecordDO::getStudentName, reqVO.getStudentName())
                .likeIfPresent(CurriculumVitaeSendRecordDO::getSex, reqVO.getSex())
                .likeIfPresent(CurriculumVitaeSendRecordDO::getCity, reqVO.getCity())
                .likeIfPresent(CurriculumVitaeSendRecordDO::getSpecialtyAbility,reqVO.getSpecialtyAbility())
                .likeIfPresent(CurriculumVitaeSendRecordDO::getLanguageAbility,reqVO.getLanguageAbility())
                .eqIfPresent(CurriculumVitaeSendRecordDO::getSpecialty, reqVO.getSpecialty())
                 .eqIfPresent(CurriculumVitaeSendRecordDO::getSendType, reqVO.getSendType())
                .likeIfPresent(CurriculumVitaeSendRecordDO::getCourses, reqVO.getCourses())
                .eqIfPresent(CurriculumVitaeSendRecordDO::getStatus, reqVO.getStatus())
                .eqIfPresent(CurriculumVitaeSendRecordDO::getSource, reqVO.getSource())
                .geIfPresent(CurriculumVitaeSendRecordDO::getPostDate,reqVO.getBeginPostDate())
                .leIfPresent(CurriculumVitaeSendRecordDO::getPostDate,reqVO.getEndPostDate())
//                .last(isAge ?"":" AND date_format(birthday，'yyyy') > "+ DateUtils.getBirthDay(reqVO.getBginAge(),"y")+" AND  date_format(birthday，'yyyy')<"+DateUtils.getBirthDay(reqVO.getBginAge(),"y"))
        );
    }


    default List<CurriculumVitaeSendRecordDO> selectList(CurriculumVitaeSendRecordExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<CurriculumVitaeSendRecordDO>()
                .likeIfPresent(CurriculumVitaeSendRecordDO::getStudentName, reqVO.getStudentName())
                .likeIfPresent(CurriculumVitaeSendRecordDO::getCompanyName, reqVO.getCompanyName())
                .likeIfPresent(CurriculumVitaeSendRecordDO::getJobName, reqVO.getJobName())
                .likeIfPresent(CurriculumVitaeSendRecordDO::getPublisherName, reqVO.getPublisherName())
                .betweenIfPresent(CurriculumVitaeSendRecordDO::getPostDate, reqVO.getBeginPostDate(), reqVO.getEndPostDate())
                .eqIfPresent(CurriculumVitaeSendRecordDO::getLiveCity, reqVO.getLiveCity())
                .likeIfPresent(CurriculumVitaeSendRecordDO::getUniversityName, reqVO.getUniversityName())
                .eqIfPresent(CurriculumVitaeSendRecordDO::getSpecialty, reqVO.getSpecialty())
                .orderByDesc(CurriculumVitaeSendRecordDO::getId));
    }


    default List<CurriculumVitaeSendRecordDO> selectList(CurriculumVitaeSendRecordPageReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<CurriculumVitaeSendRecordDO>()
                .likeIfPresent(CurriculumVitaeSendRecordDO::getStudentName, reqVO.getStudentName())
                .eqIfPresent(CurriculumVitaeSendRecordDO::getStudentId,reqVO.getStudentId())
                .likeIfPresent(CurriculumVitaeSendRecordDO::getCompanyName, reqVO.getCompanyName())
                .likeIfPresent(CurriculumVitaeSendRecordDO::getJobName, reqVO.getJobName())
                .likeIfPresent(CurriculumVitaeSendRecordDO::getPublisherName, reqVO.getPublisherName())
                .betweenIfPresent(CurriculumVitaeSendRecordDO::getPostDate, reqVO.getBeginPostDate(), reqVO.getEndPostDate())
                .eqIfPresent(CurriculumVitaeSendRecordDO::getLiveCity, reqVO.getLiveCity())
                .likeIfPresent(CurriculumVitaeSendRecordDO::getUniversityName, reqVO.getUniversityName())
                .eqIfPresent(CurriculumVitaeSendRecordDO::getSpecialty, reqVO.getSpecialty())
                .orderByDesc(CurriculumVitaeSendRecordDO::getId));
    }



    Integer countCheckInfoByJob(@Param("request") CurriculumVitaeSendRecordGroupPageReqVO reqVO);

    List<CurriculumVitaeSendRecordGroupDO> checkInfoByJob(@Param("request") CurriculumVitaeSendRecordGroupPageReqVO reqVO);

    Integer countPageByStudent(@Param("request") CurriculumVitaeSendRecordPageReqVO reqVO);

    List<CurriculumVitaeSendInviteRecordDO> selectPageByStudent(@Param("request") CurriculumVitaeSendRecordPageReqVO reqVO);

    List<CurriculumVitaeSendRecordDO> getCurriculumVitaeSendRecordList(IPage page, @Param("request") Map<String, Object> request);



    default Long noOpenCount(Long studentId){
        return selectCount(new LambdaQueryWrapperX<CurriculumVitaeSendRecordDO>()
                .eq(CurriculumVitaeSendRecordDO::getStatus, "2")
                .eq(CurriculumVitaeSendRecordDO::getStudentId, studentId)
        );
    }
    default CurriculumVitaeSendRecordDO getCurriculumVitaeSendRecordByPara(Long studentId, Long jobId, Long companyId, Long resumId){
        return selectOne(new LambdaQueryWrapperX<CurriculumVitaeSendRecordDO>()
                        .eq(CurriculumVitaeSendRecordDO::getCompanyId, companyId)
                        .eq(CurriculumVitaeSendRecordDO::getStudentId, studentId)
                        .eq(CurriculumVitaeSendRecordDO::getJobId, jobId)
                        .eq(CurriculumVitaeSendRecordDO::getResumeId, resumId)
        );
    }

}
